package gnss

import (
	"dgo/goutils/utils"
	"fmt"
	"gitee.com/ymofen/gobase"
	"sync"
	"sync/atomic"
)

var (
	gnss_sv_epoch_cnt  int32 = 0
	gnss_sv_obs_cnt    int32 = 0
	gnss_sv_obslst_cnt int32 = 0
	gnss_sv_obs_pool   sync.Pool
)

func init() {
	gnss_sv_obs_pool.New = func() interface{} {
		return newGnssSVObs()
	}

	gobase.RegisterFactoryVar("gnss.svEpochAliveN", func(sender interface{}, args ...interface{}) interface{} {
		return fmt.Sprintf("%d", atomic.LoadInt32(&gnss_sv_epoch_cnt))
	})

	gobase.RegisterFactoryVar("gnss.svObsAliveN", func(sender interface{}, args ...interface{}) interface{} {
		return fmt.Sprintf("%d", atomic.LoadInt32(&gnss_sv_obs_cnt))
	})

	gobase.RegisterFactoryVar("gnss.svStatus", func(sender interface{}, args ...interface{}) interface{} {
		return GnssSVStatus()
	})
}

func GetGnssSvPrnCode(NaviSys byte, satid uint16) string {
	if NaviSys <= 0 || NaviSys >= GNSS_SV_MAX_SYS {
		return utils.EMPTY_STRING
	}
	c := GetNavSysCode(NaviSys)

	return fmt.Sprintf("%s%.2d", c, satid)
}

func GnssSVStatus() string {
	return fmt.Sprintf("svepoch:%d, obs:%d, obslst:%d, rawsatobs:%d", gnss_sv_epoch_cnt, gnss_sv_obs_cnt, gnss_sv_obslst_cnt, rtcm_raw_sat_obs_cnt)
}

/*
*

	使用指针要不是传值
*/
func ResetSVSigListFloat64(lst *[gnsssv_sig_max]float64) {
	for i := 0; i < len(lst); i++ {
		lst[i] = 0
	}
}

func ResetSVSigListFloat32(lst *[gnsssv_sig_max]float32) {
	for i := 0; i < len(lst); i++ {
		lst[i] = 0
	}
}

func ResetSVSigListUint16(lst *[gnsssv_sig_max]uint16) {
	for i := 0; i < len(lst); i++ {
		lst[i] = 0
	}
}

func ResetSVSigListInt64(lst *[gnsssv_sig_max]int64) {
	for i := 0; i < len(lst); i++ {
		lst[i] = 0
	}
}

func ResetSVSigListInt16(lst *[gnsssv_sig_max]int16) {
	for i := 0; i < len(lst); i++ {
		lst[i] = 0
	}
}

func ResetSVSigListByte(lst *[gnsssv_sig_max]byte) {
	for i := 0; i < len(lst); i++ {
		lst[i] = 0
	}
}
